/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dao;

import com.interfaces.IMultimedia;
import com.modelo.Inmueble;
import com.modelo.Multimedia;
import java.util.List;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 *
 * @author Seysame
 */
public class MultimediaDAO extends HibernateDaoSupport implements IMultimedia {

    @Override
    public Multimedia registrarMultimedia(Multimedia multimedia) {
    
    this.getHibernateTemplate().saveOrUpdate(multimedia);
    return multimedia;
    }

    @Override
    public List<Multimedia> listarMultimedias() {
  return this.getHibernateTemplate().find("from Multimedia");
    }

    @Override
    public Multimedia buscarMultimedia(Multimedia multimedia) {
     Query query = this.getSession().createQuery("from Multimedia where id_multimedia = :id ");
     query.setParameter("id",multimedia.getIdMultimedia());
     List<Multimedia>listado = query.list();
     if(listado.isEmpty()){
     return null;
     }else{
     return listado.get(0);
     }
    
    
    }

    @Override
    public Multimedia modificarMultimedia(Multimedia multimedia) {
    this.getHibernateTemplate().saveOrUpdate(multimedia);
    return multimedia;
    
    }

    @Override
    public List<Multimedia> listarMultimediaPorInmueble(Inmueble inmueble) {
     Query query = this.getSession().createQuery("from Multimedia where id_inmueble = :id ");
     query.setParameter("id",inmueble.getIdInmueble());
     List<Multimedia>listado = query.list();
     return listado;
    
    }
    
}
